from flask import request

from approval_service.approval.service.advance_approval_service import AdvanceApprovalService
from commons.controller.base_controller import BaseController


class AdvanceApprovalController(BaseController):
    def __init__(self):
        self.advance_approval_service = AdvanceApprovalService()

    def get_advance_approval_by_id(self):
        """
        根据预支款申请审批记录ID获取预支款申请审批记录信息。
        """
        # 从请求体解析参数
        data = request.get_json()
        advance_approval_id = data.get("advanceApprovalId")

        return BaseController.get_success_response(self,
                                                   self.advance_approval_service.get_advance_approval_by_advance_approval_id(
                                                       advance_approval_id))

    def get_approve_advance_record(self):
        """
        获取审批的预支款申请记录。
        """
        # 从请求体解析参数
        data = request.get_json()
        user_id = data.get("userId")
        page_no = data.get("pageNo")
        page_size = data.get("pageSize")

        return BaseController.get_success_response(self, self.advance_approval_service.get_approve_advance_record(
            user_id, page_no, page_size))

    def get_advance_approval_by_travel_id(self):
        """
        根据TravelID获取预支款申请审批记录信息。
        """
        # 从请求体解析参数
        data = request.get_json()
        travel_id = data.get("advanceId")

        return BaseController.get_success_response(self,
                                                   self.advance_approval_service.get_advance_approval_by_travel_id(
                                                       travel_id))